/**
 * sysDicServiceImpl
 * 项目名称:分秒金融
 *
 * @author lunli
 *
 * 功能描述:数据字典管理
 * 
 * 历史版本:2017-03-27 v1.0.0 lunli  创建:
 * 
 */
package com.fmjr.sys.sysDic.service.impl;

import com.fmjr.common.base.exception.BusinessException;
import com.fmjr.common.base.util.Pager;
import com.fmjr.common.util.SqlUtil;
import com.fmjr.sys.sysDic.bean.SysDic;
import com.fmjr.sys.sysDic.dao.SysDicDao;
import com.fmjr.sys.sysDic.service.ISysDicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@CacheConfig(cacheNames = "fmjrCache")
@Service("sysDicService")
public class  SysDicServiceImpl implements ISysDicService {
	

	@Autowired
    private SysDicDao sysDicDao;

	/**
	 * 根据条件查询数据字典记录
	 * @author lunli
	 * @return SysDicList
	 * @throws BusinessException
	 */
	public void selectSysDicList(Pager<SysDic> pager) throws BusinessException{
		int totalCount = sysDicDao.selectSysDicCount(pager);
		int numPerPage = SqlUtil.checkPageSize(pager.getNumPerPage());
		int currentPage = SqlUtil.checkPageCurrent(totalCount, numPerPage, pager.getPageNum());
		pager.setLimitStart(SqlUtil.countOffset(currentPage, numPerPage));
		pager.setPageSize(numPerPage);
		pager.setCurrentPage(currentPage);
		pager.setTotalCount(totalCount);
		pager.setTotalPage(totalCount%numPerPage==0?totalCount/numPerPage:totalCount/numPerPage+1);
		List<SysDic> list = sysDicDao.selectSysDicList(pager);
		pager.setList(list);
	}
	
	/**
	 * 根据ID查询数据字典记录
	 * @author lunli
	 * @param id
	 * @return domain
	 * @throws BusinessException
	 */
	public SysDic selectSysDicById(Long id) throws BusinessException{
		return sysDicDao.selectSysDicById(id);
	}

	/**
	 *  删除数据字典记录
	 * @author lunli	 
	 * @param id
	 * @throws BusinessException
	 */
	@Transactional(rollbackFor=BusinessException.class)
	public int deleteSysDicById(Long id) throws BusinessException{
		return sysDicDao.deleteSysDicById(id);
	}
	
	/**
	 * 修改数据字典记录
	 * @author lunli
	 * @param sysDic
	 * @throws BusinessException
	 */
	@Transactional(rollbackFor=BusinessException.class)
	
	public int updateSysDic(SysDic sysDic) throws BusinessException{
		sysDic.setUpdateDate(new Date());
		return sysDicDao.updateSysDicSelective(sysDic);
	}

	/**
	 * 新增数据字典记录
	 * @author lunli
	 * @param sysDic
	 * @return
	 * @throws BusinessException
	 */
	@Transactional(rollbackFor=BusinessException.class)
	public int createSysDic(SysDic sysDic) throws BusinessException{
		sysDic.setCreateDate(new Date());
		return sysDicDao.createSysDic(sysDic);
	}

	@Override
	public List<SysDic> selectSysDicAll() throws BusinessException {
		return sysDicDao.selectSysDicAll();
	}

	@Override
	public List<SysDic> selectDicByType(String type) throws BusinessException {
		return sysDicDao.selectDicByType(type);
	}
	

	

}
